package us.versus.them.archetype;

import neko.io.File;

class Archetype {
	public static var ARTIFACT_ID_KEY  = "artifactId";
	public static var PACKAGE_NAME_KEY = "packageName";
	public static var VERSION_KEY      = "version";
	public static var TYPE_KEY         = "type";

	private static var ARCHETYPE_PACKAGE = "us.versus.them.archetype";

	public static var DEFAULT_VERSION = "1.0.0";
	public static var DEFAULT_TYPE    = "flash";

	public static function usage() {
		File.stdout().writeString(
			"\n"
			+ "usage: command [command] [-type=T] -artifactId=A -packageName=P [-version=V]\n"
			+ "command is one of: create, list\n"
			+ "eg:  create -type=flash -artifactId=myProject -packageName=us.versus.them -version=1.0.0\n"
			+ "\n"
		);
	}

	public static function main() {
		var args = Util.parseArgs( neko.Sys.args() );
		if ( null == args.get( VERSION_KEY ) ) {
			args.set( VERSION_KEY, DEFAULT_VERSION );
		}
		if ( null == args.get( TYPE_KEY ) ) {
			args.set( TYPE_KEY, DEFAULT_TYPE );
		}
		if ( null == args.get( Util.COMMAND_KEY ) ) {
			File.stdout().writeString( 'no command' );
			usage();
		} else {
			switch( args.get( Util.COMMAND_KEY ) ) {
				case "create":
					if ( null == args.get( ARTIFACT_ID_KEY ) ) {
						File.stdout().writeString( 'missing ' + ARTIFACT_ID_KEY );
						usage();
					} else {
						if ( null == args.get( PACKAGE_NAME_KEY ) ) {
							File.stdout().writeString( 'missing ' + PACKAGE_NAME_KEY );
							usage();
						} else {
							Extract.extract( args.get( TYPE_KEY ) , args );
						}
					}
				case "list": Extract.list();
				default: 
					File.stdout().writeString( 'no such command ' + args.get( Util.COMMAND_KEY ) );
					usage();
			}
		}
	}
}
